﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_members_edit_member : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request.QueryString["id"]))
        {

        }
        else
        {
            string id = Request.QueryString["id"];
            HyperLink1.NavigateUrl = "~/admin/members/profile.aspx?id=" + id;
            Member m = ACSService.getMember(Convert.ToInt32(id));

            if (m != null)
            {
                fnameBox.Text = m.FirstName;
                lnameBox.Text = m.LastName;
                emailBox.Text = m.Email;
                phoneBox.Text = m.Phone;
                studentBox.Text = m.StudentID;
                uniList.SelectedValue = Convert.ToString(m.University.ID);
                SubjectList.SelectedValue = m.SubjectArea;
                yearList.SelectedValue = m.YearOfStudy;
                DegreeList.SelectedValue = m.DegreeType;
                careerList.SelectedValue = m.CareerInterest;
                genderList.SelectedValue = m.Gender;
                ethnicityList.SelectedValue= m.Ethnicity;
                //citizenList.SelectedValue = m.UkCitizen? "true":"false";
                ageList.SelectedValue = m.AgeGroup;
                paidBox.Checked = m.Paid;

            }
            else
            {
                //redirect to members
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        int id = int.Parse(Request.QueryString["id"]);
        string fname = fnameBox.Text;
        string lname = lnameBox.Text;
        string email = emailBox.Text;
        string phone = phoneBox.Text;
        string studentid = studentBox.Text;
        int uniID = Convert.ToInt32(uniList.SelectedValue);
        string subject = SubjectList.SelectedItem.Text;
        string year = yearList.SelectedItem.Text;
        string career = careerList.SelectedItem.Text;
        string degree = DegreeList.SelectedItem.Text;
        string gender = genderList.SelectedValue.ToString();
        string ethnicity = ethnicityList.SelectedItem.Text;
        Boolean ukcitizen = false; //Convert.ToBoolean(citizenList.SelectedValue);
        string age = ageList.SelectedValue.ToString();
        Boolean paid = paidBox.Checked;

            Boolean update = ACSService.updateMember(id,fname, lname, email, phone, studentid, uniID, subject, year, degree, career, gender, ethnicity, ukcitizen, age, paid);

            if (update == true)
            {
                msgLabel.Text = "Member Updated";
                Response.Redirect("profile.aspx?id=" + id);
            }
            else
            {
                msgLabel.Text = "Error: member not updated";
            }
    }
}